#include "MountWidget.h"
#include "LoginDialog.h"
#include <QApplication>
#include "utils.h"
#include <QThread>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);


    QString appName = "jieshouji";
    QString appPath  = QCoreApplication::applicationFilePath();
    if(!Utils::isAutoRunEnabled(appName, appPath)){
        Utils::setAutoRun(appName, appPath, true); // 启用自启动
    }

    QTimer timer;
    timer.setInterval(5000); // 设置定时器间隔为1000毫秒（即1秒）
    // 使用lambda表达式连接定时器的timeout信号到输出信息的槽函数
    QObject::connect(&timer, &QTimer::timeout, [](){
        QString processName = "guard.exe";
        QString command1 = "tasklist";
        QProcess process;
        QStringList arguments1;
        arguments1 << "/FI" << QString("IMAGENAME eq %1").arg(processName);

        process.start(command1, arguments1);
        process.waitForFinished();
        QByteArray output = process.readAllStandardOutput();
        QString outputStr = QString::fromLocal8Bit(output);

        if (outputStr.contains(processName)) {
            qDebug() << processName << "正在运行";
        }
        else{
            //QStringList arguments;
            //arguments << QFileInfo(QCoreApplication::applicationFilePath()).fileName() << QString::number(configwatchdog.checkInterval);
            QString process = QCoreApplication::applicationFilePath().replace("Upan2.exe", "guard.exe");
            QProcess::startDetached(process, QStringList(process));
        }
    });
    timer.start(); // 启动定时器


//    Widget w;
//    w.show();
    Dialog d;
    d.show();
    return a.exec();
}
